/*******************************************************************************
* This file provides the functions for the ADC module.
*
* Author: Kong Wai Weng @ Cytron Technologies Sdn. Bhd.
*******************************************************************************/



#ifndef _HAL_ADC_H
#define _HAL_ADC_H



#include <adc.h>
#include <dma.h>
#include "system.h"
#include "variables.h"



/*******************************************************************************
* PUBLIC FUNCTION PROTOTYPES                                                   *
*******************************************************************************/

/*******************************************************************************
* PUBLIC FUNCTION: vInitAdc
*
* PARAMETERS:
* ~ void
*
* RETURN:
* ~ void
*
* DESCRIPTIONS:
* Initialize the ADC module.
*
*******************************************************************************/
void vInitAdc(void);



/*******************************************************************************
* PUBLIC FUNCTION: uiReadAdc
*
* PARAMETERS:
* ~ ucChannel	- The ADC channel that we want to read.
*
* RETURN:
* ~ The ADC result.
*
* DESCRIPTIONS:
* Read the ADC result
*
*******************************************************************************/
unsigned int uiReadAdc(unsigned char ucChannel);



/*******************************************************************************
* PUBLIC FUNCTION: uiReadVin
*
* PARAMETERS:
* ~ void
*
* RETURN:
* ~ The voltage of Vin in mV.
*
* DESCRIPTIONS:
* Read the voltage of Vin.
*
*******************************************************************************/
unsigned int uiReadVin(void);



/*******************************************************************************
 * PUBLIC FUNCTION: vCalibrateCurrentOffset
 *
 * PARAMETERS:
 * ~ void
 *
 * RETURN:
 * ~ void
 *
 * DESCRIPTIONS:
 * Calibrate the current sensor offset.
 *
 *******************************************************************************/
void vCalibrateCurrentOffset(void);



/*******************************************************************************
 * PUBLIC FUNCTION: uiReadCurrent
 *
 * PARAMETERS:
 * ~ void
 *
 * RETURN:
 * ~ The current in mA.
 *
 * DESCRIPTIONS:
 * Read the current.
 *
 *******************************************************************************/
unsigned int uiReadCurrent(void);



#endif
